﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ECCIT;
using ECCIT.Utilities;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;

public partial class GateService_CalendarInterface : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            var cmd = Request.Params["cmd"];
            var  sLangID = Request.Params["langID"];       
            int lanagerid = 1033;
            if(!int.TryParse(sLangID,out lanagerid))
            {
                lanagerid = 1033;
            }
            int memberid = 0;
            var id = new AccountController(lanagerid).AccountInfo.ID;
            if (id!=null&&id > 0)
            {
                memberid = (int)id;
            }
            DataTable dt;

            switch (cmd)
            {
                case "Add":
                    var eventID = Request.QueryString["eventID"];
                    int ieventID = 0;
                    if (!int.TryParse(eventID, out ieventID))
                    {
                        ShowMessage(CommonConst.OperateError);
                        return;
                    }
              
                    var model = new EventCalendarModel(memberid, ieventID,lanagerid);                  
                    ResultInfo resultInfo = new EventCalendarBLL(lanagerid).Save(model);
                    if (resultInfo.Result)
                    {
                        ShowMessage(resultInfo.Message,"HideCalendar()");
                    }
                    else
                    {
                        ShowMessage(resultInfo.Message);
                    }
                   
                    break;
                case "RemenderAll":
                   if( new RemberSetBLL(lanagerid).RemindarAll(memberid))
                   {
                       ShowMessage(CommonConst.OperateSucc, "HideRemenderAll()");
                   }
                    break;
                case "ClearRemender":
                    if (new RemberSetBLL(lanagerid).ClearRemindar(memberid))
                    {
                        ShowMessage(CommonConst.OperateSucc);
                    }
                    break;
                case "MyFavEvents":
                    // dt = new EventsBLL(lanagerid).GetMyEvents(memberid, "", "", true);
                    //if(dt!=null&&dt.Rows.Count>0)
                    //{
                    //    Responseobj(JsonUtil.Serialize(dt));
                    //}
                    //else
                    //{
                        
                    //}
                    break;
                case "MyLatestEvents":
                    //  dt = new EventsBLL(lanagerid).GetMyEvents(memberid, "", "", true);
                    //if(dt!=null&&dt.Rows.Count>0)
                    //{
                    //    Responseobj(JsonUtil.Serialize(dt));
                    //}
                    //else
                    //{
                        
                    //}
                    break;
                case "EventRemenderSetting":
                    var COL_REM_EMAIL = Request.QueryString["emall"];
                    var COL_REM_BY_EMAIL = Request.QueryString["byemall"] != null && bool.Parse(Request.QueryString["byemall"]);
                    var COL_REM_MOBILE = Request.QueryString["mobile"];
                    var COL_REM_BY_MOBILE= Request.QueryString["bymobile"] != null && bool.Parse(Request.QueryString["bymobile"]);
                    var Settingmodel = new MemberReminderSettingModel();
                    Settingmodel.COL_MEMBER_ID = memberid;
                    Settingmodel.COL_REM_EMAIL = COL_REM_EMAIL;
                    Settingmodel.COL_REM_BY_EMAIL = COL_REM_BY_EMAIL;
                    Settingmodel.COL_REM_MOBILE = COL_REM_MOBILE;
                    Settingmodel.COL_REM_BY_MOBILE = COL_REM_BY_MOBILE;

                    if (new RemberSetBLL(lanagerid).Set(Settingmodel))
                    {
                        ShowMessage(CommonConst.OperateSucc);
                    }

                    break;
                //case "MyCommentOrUpLoads":
                //    break;
                //case "DelCommentOrUpLoads":
                //    break;
                case "MyProFile":
                    var prodt = new MemberBLL(lanagerid).GetMyProfile(memberid, "", "");
                    //var intersdt = new MemberBLL(lanagerid).GetMyInterests(memberid);

                    //修改显示
                    //var intersmodifydt = new ArtFormBLL(lanagerid).GetModifyMyProfile(memberid, lanagerid);

                    //提交 基本信息                  
                    new MemberBLL(lanagerid).Save(new MemberModel() {});
                    //兴
                    IList<MemberIntersetsMappingModel>  list=new List<MemberIntersetsMappingModel>();
                    list.Add(new MemberIntersetsMappingModel(){});

                    new MemberIntersetsMappingBLL(lanagerid).Save(list);



                    break;
                case "AddRemender":
                    var AddeventID = Request.QueryString["eventID"];
                    int IAddeventID = 0;
                    if (!int.TryParse(AddeventID, out IAddeventID))
                    {
                        ShowMessage(CommonConst.OperateError);
                        return;
                    }
                    MemberReminderMappingModel Remindermodel = new MemberReminderMappingModel
                                                                   {
                                                                       MEMBER_ID = memberid,
                                                                       COL_LANG_ID = lanagerid,
                                                                       COL_EVENTS_ID = IAddeventID
                                                                   };
                    ResultInfo result = new MemberReminderBLL(lanagerid).Save(Remindermodel);
                    if (result.Result)
                    {
                        ShowMessage(result.Message, "HideRemender()");
                    }
                    else
                    {
                        ShowMessage(result.Message);
                    }
                    break;
    
            }
        }
    }

    private void Responseobj(string obj)
    {
        Response.Write(obj);
    }

    private void ShowMessage(string message,string jsfuction)
    {
        Response.Write(string.Format("alert('{0}');{1};", message, jsfuction));
    }
    private void ShowMessage(string message)
    {
        Response.Write(string.Format("alert('{0}');",message));
    }

}